import {defineStore} from 'pinia'
import {reqHistory,reqRoomAll,reqDelHistory,reqSearch,reqClass} from '../api/training/training'
let useTrainingStore = defineStore('training',{
    state:():any=>({
        // 我的练习室全部
        Roomlist:[],
        // 历史
        HistoryList:[],
        //历史搜索
        SearchList:[],
        // 练习室里面
        ClassList:[]
    }),
    actions:{
        // 获取历史
        async getHistory(pageSize:number,pageNum:number){
            try{
                let result = await reqHistory(pageSize,pageNum)
                console.log(result);
                this.HistoryList = result
                this.HistoryList.content.forEach((item:any) => {
                    item.flag = false
                    item.url = item.momentBackup.router.slice(6)
                });
            }catch(e){
                return e
            }

            
        },
        // 获取我的练习室全部
        async getRoomAll(pageSize:number,pageNum:number,type:string,myListCategory:string){
            try{
                let result = await reqRoomAll(pageSize,pageNum,type,myListCategory)
                console.log(result);
                this.Roomlist = result
            }catch(e){
                return e
            }
        },
        // 删除历史
        async getDelHistory(ids:any){
                await reqDelHistory(ids)
        },
        //历史关键字搜索
        async getSearch(pageSize:number,pageNum:number,keyword:string){
            try{
                let result = await reqSearch(pageSize,pageNum,keyword)
                console.log(result);    
                this.HistoryList = result
                this.HistoryList.numberOfElements = result.content.length
            }catch(e){
                return e
            }

        },
        //获取课堂页
        async getClassList(pageSize:number,pageNum:number,planId:string){
            try{
                let result = await reqClass(pageSize,pageNum,planId)
                console.log(result);
                result.content.forEach((item:any)=>{
                    item.url = item.router.slice(6)
                })
                this.ClassList = result
            }catch(e){
                return e
            }
        }
    }
})
export default useTrainingStore